﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using GameSchool.Models;

namespace GameSchool.Controllers
{
    public class ExamController : Controller
    {
        GameSchoolRepository repository = new GameSchoolRepository();
        ExamsViewModel examview = new ExamsViewModel();
        //
        // GET: /Exam/
        #region Views

        //For students
        public ActionResult ViewExam(int CID)
        {
            ExamsStudentViewModel viewmodel = new ExamsStudentViewModel();
            var studentLogin = repository.GetStudentLoginRelationship();

            viewmodel.studentName = studentLogin.name; //For the top bar
            viewmodel.sidebarCourses = repository.GetCoursesByStudent(studentLogin).ToList();
			return View(viewmodel);
        }

        //For teachers
        public ActionResult CreateExam(int CID,int LVID)
        {
            ExamsViewModel exem = new ExamsViewModel();
            Exam relevant = new Exam();

            var teacherLogin = repository.GetTeacherLoginRelationship();
            exem.loggedInTeacher = teacherLogin;
            exem.sidebarCourses = repository.GetCoursesByTeacher(teacherLogin).ToList();
            exem.teacherName = teacherLogin.name;
            relevant = repository.GetExamByLevelID(LVID);
            exem.LevelID = LVID;
            exem.courseID = CID;
            exem.examID = relevant.examID;
            exem.examXP = relevant.examXP;
            exem.examTitle = relevant.title;
            exem.examDescription = relevant.description;
            exem.examTimeLimit = relevant.timeLimit;
            //exem.inputExam = relevant.examInput;
         
     

            return View(exem);
        }

        [HttpPost]
        public ActionResult CreateExam(FormCollection formData)
        {
            Exam currentExam = new Exam();

           
           currentExam.levelID = Convert.ToInt32(formData["levelID"]);
           var courseID = Convert.ToInt32(formData["courseID"]);
           var examID = Convert.ToInt32(formData["examID"]);
           currentExam.examXP = Convert.ToInt32(formData["examXP"]);
           currentExam.title = formData["examTitle"];
           currentExam.description = formData["examdescription"];
           currentExam.timeLimit = Convert.ToInt32(formData["examTimeLimit"]);
           //currentExam.examInput = Request.Form["Hidden1"];
           


           repository.UpdateExam(currentExam);
           repository.Save();

            return Redirect("~/Exam/ViewExam");
        }

        //For teachers
        public ActionResult ExamEdit(int id)
        {
            return View();
        }

        [HttpPost]
        public ActionResult ExamEdit(int id, FormCollection formData)
        {
            return View();
        }

        #endregion

        public Notification GetNotifications(Notification theNotification)
        {
            return theNotification;
        }
    }
}
